package com.ruoyi.hippocampus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hippocampus.domain.EmployeeRole;
import com.ruoyi.hippocampus.service.IEmployeeRoleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工职务Controller
 * 
 * @author ruoyi
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/hippocampus/employeerole")
public class EmployeeRoleController extends BaseController
{
    @Autowired
    private IEmployeeRoleService employeeRoleService;

    /**
     * 查询员工职务列表
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:employeerole:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmployeeRole employeeRole)
    {
        startPage();
        List<EmployeeRole> list = employeeRoleService.selectEmployeeRoleList(employeeRole);
        return getDataTable(list);
    }

    /**
     * 导出员工职务列表
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:employeerole:export')")
    @Log(title = "员工职务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmployeeRole employeeRole)
    {
        List<EmployeeRole> list = employeeRoleService.selectEmployeeRoleList(employeeRole);
        ExcelUtil<EmployeeRole> util = new ExcelUtil<EmployeeRole>(EmployeeRole.class);
        util.exportExcel(response, list, "员工职务数据");
    }

    /**
     * 获取员工职务详细信息
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:employeerole:query')")
    @GetMapping(value = "/{employeeId}")
    public AjaxResult getInfo(@PathVariable("employeeId") Long employeeId)
    {
        return AjaxResult.success(employeeRoleService.selectEmployeeRoleByEmployeeId(employeeId));
    }

    /**
     * 新增员工职务
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:employeerole:add')")
    @Log(title = "员工职务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmployeeRole employeeRole)
    {
        return toAjax(employeeRoleService.insertEmployeeRole(employeeRole));
    }

    /**
     * 修改员工职务
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:employeerole:edit')")
    @Log(title = "员工职务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmployeeRole employeeRole)
    {
        return toAjax(employeeRoleService.updateEmployeeRole(employeeRole));
    }

    /**
     * 删除员工职务
     */
    @PreAuthorize("@ss.hasPermi('hippocampus:employeerole:remove')")
    @Log(title = "员工职务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{employeeIds}")
    public AjaxResult remove(@PathVariable Long[] employeeIds)
    {
        return toAjax(employeeRoleService.deleteEmployeeRoleByEmployeeIds(employeeIds));
    }
}
